{% extends 'base.html' %}

{% block title %}
    提交模块
{% endblock %}

{% block info %}
    提交模块
{% endblock %}

{% block info1 %}
    提交模块
{% endblock %}

{% block main %}
    <div class="row">
        <div class="col-lg-12">
            <div class="card m-b-30">
                <div class="card-body"><h4 class="mt-0 header-title">模块提交</h4>
                    <form class="" action="#" novalidate="">
                        <div class="form-group"><label>名字</label> <input type="text" class="form-control" id="name">
                        </div>
                        <div class="form-group"><label>SRC</label>
                            <div><input type="text" id="src" class="form-control"></div>
                        </div>
                        <div class="form-group"><label>回调参数值</label>
                            <div><input type="text" class="form-control" id="callback"></div>
                        </div>
                        <div class="form-group"><label>数据字段</label>
                            <div><input type="text" class="form-control" id="columns"></div>
                        </div>
                        <div class="form-group"><label>信息展示地址</label>
                            <div><input type="text" class="form-control" id="url"></div>
                        </div>
                        <div class="form-group"><label>模块描述</label>
                            <div><input type="text" class="form-control" id="commit"></div>
                        </div>
                        <div class="form-group">
                            <div>
                                <button type="submit" class="btn btn-primary waves-effect waves-light" id="submit">Submit</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
{% endblock %}
{% block js %}
    <script>
        $("#submit").click(function (event) {
            var url = "{{ url_for('add_plugin') }}";
            $.ajax({
                type: "POST",
                url: url,
                data: {
                    "name": $("#name").val(),
                    "src": $("#src").val(),
                    "callback": $("#callback").val(),
                    "columns": $("#columns").val(),
                    "url": $("#url").val(),
                    "commit": $("#commit").val()
                },
                dataType: "json",
                success: function (json) {
                    message = JSON.parse(JSON.stringify(json))
                    if (message['success'] == 1) {
                        alert(message['message']);
                        window.location.href = message['url'];
                    } else {
                        alert(message['message']);
                    }
                }
            });
        });
    </script>
{% endblock %}